From dad18c78cb52afe5428abf5403725118a285e641 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Mon, 28 Nov 2005 11:05:07 +0000 Subject: [PATCH] Change uses of \s within sed regexps -- some versions of sed do not support this escape. Allow the vif-nat and vif-route scripts to have netdev specified, rather than hard-coding eth0. Signed-off-by: Ewan Mellor --- tools/examples/README.incompatibilities | 6 +++++ tools/examples/vif-common.sh | 34 +++++++++++++++++++++++++ tools/examples/vif-nat | 2 +- tools/examples/vif-route | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/examples/README.incompatibilities b/tools/examples/README.incompatibilities index 2d2c9503cf..87b2dbd62e 100644 --- a/tools/examples/README.incompatibilities +++ b/tools/examples/README.incompatibilities @@ -23,3 +23,9 @@ appropriately. See xen-network-common.sh for details. Gentoo doesn't have ifup/ifdown; appropriate alternatives are defined in xen-network-common.sh. + +sed +--- + +\s is not supported in regexps on Debian etch (sed 4.1.2), Ubuntu 4.10. We +hand-craft character classes instead. diff --git a/tools/examples/vif-common.sh b/tools/examples/vif-common.sh index f7a488082a..18a0b6c88e 100644 --- a/tools/examples/vif-common.sh +++ b/tools/examples/vif-common.sh @@ -103,3 +103,37 @@ function handle_iptable() frob_iptable fi } + + +## +# ip_of interface +# +# Print the IP address currently in use at the given interface, or nothing if +# the interface is not up. +# +function ip_of() +{ + ip addr show "$1" | sed -n 's/^.*inet \([0-9.]*\).*$/\1/p' +} + + +## +# dom0_ip +# +# Print the IP address of the interface in dom0 through which we are routing. +# This is the IP address on the interface specified as "netdev" as a parameter +# to these scripts, or eth0 by default. This function will call fatal if no +# such interface could be found. +# +function dom0_ip() +{ + local nd=${netdev:-eth0} + local result=$(ip_of "$nd") + if [ -z "$result" ] + then + fatal +"$netdev is not up. Bring it up or specify another interface with " \ +"netdev= as a parameter to $0." + fi + echo "$result" +} diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat index 653038f223..f94829689c 100644 --- a/tools/examples/vif-nat +++ b/tools/examples/vif-nat @@ -37,7 +37,7 @@ netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 )) netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 )) netmask=$netmask.$(( $intmask & 0x000000FF )) -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/') +main_ip=$(dom0_ip) case "$command" in online) diff --git a/tools/examples/vif-route b/tools/examples/vif-route index 84a6f2d0c6..d733119d30 100755 --- a/tools/examples/vif-route +++ b/tools/examples/vif-route @@ -23,7 +23,7 @@ dir=$(dirname "$0") . "$dir/vif-common.sh" -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/') +main_ip=$(dom0_ip) case "$command" in online) -- 2.30.2